using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

public class JsonEx
{
    public static T ReadJsonToObject<T>(string filepath)
    {
        T obj = default(T);

        if (!File.Exists(filepath))
        {
            return obj;
        }

        StreamReader sr = new StreamReader(filepath);

        if (sr == null)
        {
            return obj;
        }
        string json = sr.ReadToEnd();

        if (json.Length <= 0)
        {
            return obj;
        }

        try
        {
            obj = JsonUtility.FromJson<T>(json);
        }
        catch (Exception e)
        {
            Debug.Log(e);
        }
        return obj;
    }
}